package com.rd.student.jiaji.class3.zhangshixuan.Day0731;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo05 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        for (int i = 0; i < 50; i++) {
            list.add(i);
        }
        int len=list.size();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要随机的个数：");
        int n = scanner.nextInt();
        ArrayList<Integer> eleList1 = new ArrayList<>();
        while (eleList1.size() < n) {
            int random = (int) (Math.random() * len);
            int ele = (int)list.get(random);
            if (!eleList1.contains(ele)) {
                System.out.println("添加元素：" + ele);
                eleList1.add(ele);
            } else {
                System.out.println("重复元素：" + ele);
            }
        }
        System.out.println(eleList1);
    }
}
